package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"os"
	"os/signal"
	"server/app/api"
	"server/base"
	"server/base/intialize"
	"syscall"
)

func main() {
	// 初始化系统配置
	intialize.Base{}.Init()

	// 启动系统基础服务
	intialize.Base{}.Run()

	// 创建服务并把路由转接给http服务的route处理
	r := api.Router{}.Init(gin.Default())

	// 启动系统服务
	go func() {
		err := r.Run(fmt.Sprintf(":%d", base.App.Config.Http.Port))
		if err != nil {
			fmt.Println("服务启动失败", err.Error())
		}
	}()

	quit := make(chan os.Signal)
	signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
	<-quit
	fmt.Println("Server exiting")
}
